/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.io.fasta;

import java.io.IOException;
import java.io.Reader;

import phoside.Proteins;

import phoside.io.ProteinsReader;
import phoside.io.fasta.parser.HeaderRule;
import phoside.io.fasta.util.FastaReaderTraveler;

/**
 *
 * @author gjj
 */
public class DefaultFastaProteinsReader implements ProteinsReader {
    protected final Reader reader;
    protected final ProteinsReaderFastaVisitor visitor;

    public DefaultFastaProteinsReader(final Reader reader,
            final Proteins proteins, final HeaderRule headerRule) {
        this (reader, new ProteinsReaderFastaVisitor(proteins, headerRule));
    }

    public DefaultFastaProteinsReader(final Reader reader,
            final ProteinsReaderFastaVisitor visitor) {
        if (reader==null || visitor==null) {
            throw new java.lang.IllegalArgumentException();
        }

        this.reader = reader;
        this.visitor = visitor;
    }


    /**
     * Reader phosphorylation data
     * @return data stored in PhosphoData if successful, null otherwise.
     */
    public Proteins read() throws IOException {
        final FastaReaderTraveler traveler = new FastaReaderTraveler(reader, visitor);
        traveler.travel();
        return visitor.getProteins();
    }
}
